package gxb.test08;
class Account{

    private String name;
    private long acctNum;
    private double balance;

    public Account( String name, long acctNun,double balance) {

        this.name = name;
        this.acctNum = acctNum;//账户号码
        this.balance = balance;//表示余额
    }
    public void withdraw(double amount){
        if (balance>=amount) balance-=amount;
        else System.out.println("Insufficient funds");
    }
    //存款
    public void deposit(double amount){
        balance+=amount;
    }

    public double getBalance() {
        return balance;
    }

    @Override
    public String toString() {
        return "Account{" +
                "name=" + name +
                ",balance='" + balance + '\'' +
                ", acctNum=" + acctNum +
                '}';
    }

    public double chargeFee(double fee){
        balance = balance - fee;
        return balance;
    }
    public void changeName(String newName){
        this.name=newName;
    }
}
public class ManageAccounts {
    public static void main(String[] args) {
        Account acct1,acct2;
        acct1 = new Account("Sally",1000,1111);
        acct2 = new Account("Joe",500,1112);
        acct1.deposit(100);
        System.out.println(acct2.getBalance());
        acct1.withdraw(50);
        System.out.println(acct1.getBalance());
        acct1.chargeFee(10);
        acct2.chargeFee(10);
        acct2.changeName("Joseph");
        System.out.println(acct1.toString());
        System.out.println(acct2.toString());
    }
}
